home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / sharewar / FFE / GRAPH.SWG / 0032_METAFILE (WMF).pas < prev    next >
Pascal/Delphi Source File  |  1997-05-11  |  8KB  |  201 lines

  1. .WMF Metafile Format
  2.  
  3. A metafile for the Microsoft Windows operating system consists of a collection of graphics device interface (GDI) functions that 
  4. describe an image. Because metafiles take up less space and are more device-independent than bitmaps, they provide 
  5. convenient storage for images that appear repeatedly in an application or need to be moved from one application to another. 
  6. To generate a metafile, a Windows application creates a special device context that sends GDI commands to a file or memory for 
  7. storage. The application can later play back the metafile and display the image. 
  8. During playback, Windows breaks the metafile down into records and identifies each object with an index to a handle table. When 
  9. a META_DELETEOBJECT record is encountered during playback, the associated object is deleted from the handle table. The
  10. entry is then reused by the next object that the metafile creates. To ensure compatibility, an application that explicitly manipulates 
  11. records or builds its own metafile should manage the handle table in the same way. For more information on the format of the 
  12. handle table, see the HANDLETABLE structure. 
  13.  
  14. In some cases, there are two variants of a metafile record, one representing the record created by Windows versions before 3.0 
  15. and the second representing the record created by Windows versions 3.0 and later. Windows versions 3.0 and later play all 
  16. metafile versions but store only 3.0 and later versions. Windows versions earlier than 3.0 do not play metafiles recorded by 
  17. Windows versions 3.0 and later. 
  18. A metafile consists of two parts: a header and a list of records. The header and records are described in the remainder of this 
  19. topic. For a list of function-specific records, see Metafile Records. 
  20.  
  21. Metafile Header
  22.  
  23. The metafile header contains a description of the size of the metafile and the number of drawing objects it uses. The drawing 
  24. objects can be pens, brushes, bitmaps, or fonts. 
  25. The metafile header has the following form:
  26.  
  27.  
  28.  
  29. typedef struct tagMETAHEADER {
  30.     WORD  mtType;
  31.     WORD  mtHeaderSize;
  32.     WORD  mtVersion;
  33.     DWORD mtSize;
  34.     WORD  mtNoObjects;
  35.     DWORD mtMaxRecord;
  36.     WORD  mtNoParameters;
  37. } METAHEADER;
  38.  
  39. Following are the members in the metafile header: 
  40.  
  41. mtType    Specifies whether the metafile is stored in memory or recorded in a file. This member has one of the 
  42. following values: 
  43.  
  44. Value    Meaning
  45.  
  46. 0    Metafile is in memory. 
  47. 1    Metafile is in a file. 
  48.  
  49. mtHeaderSize    Specifies the size, in words, of the metafile header.
  50. mtVersion    Specifies the Windows version number. The version number for Windows version 3.0 and later is 0x300. 
  51. mtSize    Specifies the size, in words, of the file. 
  52. mtNoObjects    Specifies the maximum number of objects that can exist in the metafile at the same time. 
  53. mtMaxRecord    Specifies the size, in words, of the largest record in the metafile. 
  54. mtNoParameters    Not used. 
  55.  
  56. Typical Metafile Record
  57.  
  58. The graphics device interface stores most of the GDI functions that an application can use to create metafiles in typical records. 
  59. A typical metafile record has the following form: 
  60.  
  61.  
  62.  
  63. struct {
  64.     DWORD rdSize;
  65.     WORD  rdFunction;
  66.     WORD  rdParm[];
  67. }
  68.  
  69. Following are the members in a typical metafile record:
  70.  
  71. rdSize    Specifies the size, in words, of the record. 
  72. rdFunction    Specifies the function number. This value may be the number of any function in the table at the end of this section. 
  73. rdParm    Identifies an array of words containing the function parameters (listed in the reverse order in which they are
  74. passed to the function). 
  75.  
  76. Following are the GDI functions found in typical records, along with their hexadecimal values: 
  77.  
  78. GDI function    Value
  79.  
  80. Arc    0x0817 
  81. Chord    0x0830
  82. Ellipse    0x0418 
  83. ExcludeClipRect    0x0415 
  84. FloodFill    0x0419 
  85. IntersectClipRect    0x0416
  86. LineTo    0x0213 
  87. MoveTo    0x0214 
  88. OffsetClipRgn    0x0220 
  89. OffsetViewportOrg    0x0211 
  90. OffsetWindowOrg    0x020F 
  91. PatBlt    0x061D 
  92. Pie    0x081A 
  93. RealizePalette (3.0 and later)    0x0035
  94.  
  95. Rectangle    0x041B 
  96. ResizePalette (3.0 and later)    0x0139 
  97. RestoreDC    0x0127
  98. RoundRect    0x061C 
  99. SaveDC    0x001E 
  100. ScaleViewportExt    0x0412 
  101. ScaleWindowExt    0x0400 
  102. SetBkColor    0x0201 
  103. SetBkMode    0x0102 
  104. SetMapMode    0x0103 
  105. SetMapperFlags    0x0231
  106. SetPixel    0x041F 
  107. SetPolyFillMode    0x0106 
  108. SetROP2    0x0104 
  109.  
  110. SetStretchBltMode    0x0107 
  111. SetTextAlign    0x012E 
  112. SetTextCharacterExtra    0x0108 
  113. SetTextColor    0x0209 
  114. SetTextJustification    0x020A 
  115. SetViewportExt    0x020E 
  116. SetViewportOrg    0x020D 
  117. SetWindowExt    0x020C
  118. SetWindowOrg    0x020B 
  119.  
  120. Placeable Windows Metafiles
  121.  
  122. A placeable Windows metafile is a standard Windows metafile that has an additional 22-byte header. The header contains 
  123. information about the aspect ratio and original size of the metafile, permitting applications to display the metafile in its intended 
  124. form. 
  125. The header for a placeable Windows metafile has the following form: 
  126.  
  127.  
  128.  
  129. typedef struct {
  130.     DWORD   key;
  131.     HANDLE  hmf;
  132.     RECT    bbox;
  133.     WORD    inch;
  134.     DWORD   reserved;
  135.     WORD    checksum;
  136. } METAFILEHEADER;
  137.  
  138. Following are the members of a placeable metafile header: 
  139.  
  140. key    Specifies the binary key that uniquely identifies this file type. This member must be set to 0x9AC6CDD7L. 
  141. hmf    Unused; must be zero.
  142. bbox    Specifies the coordinates of the smallest rectangle that encloses the picture. The coordinates are in metafile units 
  143. as defined by the inch member. 
  144. inch    Specifies the number of metafile units to the inch. To avoid numeric overflow, this value should be less than 1440. 
  145. Most applications use 576 or 1000.
  146. reserved    Unused; must be zero. 
  147. checksum    Specifies the checksum. It is the sum (using the XOR operator) of the first 10 words of the header. 
  148.  
  149. The actual content of the Windows metafile immediately follows the header. The format for this content is identical to that for 
  150. standard Windows metafiles. For some applications, a placeable Windows metafile must not exceed 64K. 
  151.  
  152. Note:    Placeable Windows metafiles are not compatible with the GetMetaFile function. Applications that intend to use the metafile 
  153. functions to read and play placeable Windows metafiles must read the file by using an input function (such as _lread), strip
  154. the 22-byte header, and create a standard Windows metafile by using the remaining bytes and the SetMetaFileBits 
  155. function. 
  156.  
  157. Guidelines for Windows Metafiles
  158.  
  159. To ensure that metafiles can be transported between different computers and applications, any application that creates a 
  160. metafile should make sure the metafile is device-independent and sizable. 
  161. The following guidelines ensure that every metafile can be accepted and manipulated by other applications: 
  162.  
  163.     Set a mapping mode as one of the first records. Many applications, including OLE applications, only accept metafiles that are 
  164. in MM_ANISOTROPIC mode. 
  165.  
  166.     Call the SetWindowOrg and SetWindowExt functions. Do not call the SetViewportExt or SetViewportOrg functions if 
  167. the user will be able to resize or change the dimensions of the object. 
  168.  
  169.     Use the MFCOMMENT printer escape to add comments to the metafile.
  170.  
  171.     Rely primarily on the functions listed in Typical Metafile Record. Observe the following limitations on the functions you use: 
  172.  
  173.     Do not use functions that retrieve data (for example, GetActiveWindow or EnumFontFamilies). 
  174.  
  175.     Do not use any of the region functions (because they are device dependent). 
  176.  
  177.     Use StretchBlt or StretchDIB instead of BitBlt.
  178.  
  179. Sample of Metafile Program Output
  180.  
  181. This section describes a sample program and the metafile that it creates. The sample program creates a small metafile that
  182. draws a purple rectangle with a green border and writes the words "Hello People" in the rectangle. 
  183.  
  184.  
  185.  
  186. MakeAMetaFile(hDC)
  187. HDC hDC;
  188. {
  189.     HPEN     hMetaGreenPen;
  190.     HBRUSH   hMetaVioletBrush;
  191.     HDC      hDCMeta;
  192.     HANDLE   hMeta;
  193.  
  194.     /* Create the metafile with output going to the disk. */
  195.  
  196.     hDCMeta = CreateMetaFile( (LPSTR) "sample.met");
  197.  
  198.     hMetaGreenPen = CreatePen(0, 0, (DWORD) 0x0000FF00);
  199.     SelectObject(hDCMeta, hMetaGreenPen);
  200.  
  201.     hMetaVioletBrus